package com.jinyi.wwdeng.ui.user.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.jinyi.lib_baseadapter.BGARecyclerViewAdapter
import com.jinyi.lib_baseadapter.BGAViewHolderHelper
import com.jinyi.wwdeng.R
import org.json.JSONObject

/**
 * JinYiTest
 * @Author wwdeng
 * @CreateTime: 2024/4/19 12:02
 * @Annotation：意见反馈 - 联系方式列表
 */
class UserFeedbackContactAdapter(recyclerView: RecyclerView?): BGARecyclerViewAdapter<JSONObject>(recyclerView,R.layout.item_feedback_contact) {

    override fun setItemChildListener(helper: BGAViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.btnCopy) //复制
        helper.setItemChildClickListener(R.id.btnDial)//拨号
    }

    override fun fillData(helper: BGAViewHolderHelper, position: Int, model: JSONObject) {
        helper.setText(R.id.tvValue,model.optString("value"))
        //图标
        val imgIcon = helper.getImageView(R.id.imgIcon)
        val type = model.optString("type")
        when(type){
            "MOBILE" -> {//电话
                imgIcon.setImageResource(R.mipmap.pic_user_feedback_phone_icon)
                helper.setText(R.id.tvType,mContext.getString(R.string.phone_number))
                helper.setVisibility(R.id.btnDial, View.VISIBLE)
            }
            else -> {//邮箱
                imgIcon.setImageResource(R.mipmap.pic_user_feedback_email_icon)
                helper.setText(R.id.tvType,mContext.getString(R.string.e_mail))
                helper.setVisibility(R.id.btnDial, View.GONE)
            }
        }

        if (position == itemCount - 1){
            helper.setVisibility(R.id.vLine, View.GONE)
        } else {
            helper.setVisibility(R.id.vLine, View.VISIBLE)
        }
    }
}